﻿using Microsoft.Extensions.DependencyInjection;
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using QiAdmin.Model.Dtos.Input;
using QiAdmin.Service.IService;

namespace QiAdmin.Core.Services.QuartzService
{
    public class BaseJobService
    {
        public void Execute(IJobExecutionContext context, Func<bool> func)
        {
            try
            {
                bool result = func();
                using (var serviceScope = App.Instance.CreateScope())
                {
                    ITSysTaskLogService tSysTaskLogService = serviceScope.ServiceProvider.GetService<ITSysTaskLogService>();
                    TSysTaskLog_IN sysTask = new TSysTaskLog_IN
                    {
                        TaskId = Convert.ToInt32(context.JobDetail.Key.Name),
                        Status = result ? "10" : "00"
                    };
                    tSysTaskLogService.Add(sysTask);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("定时任务执行异常:" + ex.Message);
            }
        }
    }
}
